using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Skill_TimeEcho : Skill_Base
{
    [Header("Regular Time Echo")]
    [SerializeField] private GameObject regularTimeEchoPrefab;
    [SerializeField] private float lifeDuration;
    public float GetLifeDuration => lifeDuration;

    [Header("Time Echo Attack Upgrade")]
    [SerializeField] private int singleAttackCount = 1;
    [SerializeField] private int maxAttackCount = 3;
    [SerializeField] private float multiplyProbability = .6f;
    [SerializeField] private int maxMultiplyCount = 2;

    [Header("Heal wisp Upgrade")]
    [SerializeField] private float damagePercentHealed = .3f; //敌人伤害的百分比，转换成血量加成
    [SerializeField] private float cooldownReducedInSeconds; //减少的技能冷却时间
    private int currentMutiply;
    protected override void Awake()
    {
        base.Awake();
        currentMutiply = maxMultiplyCount;
    }
    public override bool CanUseSkill()
    {
        if (base.CanUseSkill() == false)
            return false;
        if (player.stateMachine.currentState == player.domainExpansionState)
            return false;
        return true;
    }
    public override void TryUseSkill()
    {
        if (CanUseSkill() == false)
            return;
        currentMutiply = maxMultiplyCount;
        CreateTimeEcho();
    }
    public void SetCurrentMutiply() => currentMutiply--;
    public bool CanMutiply()
    {
        if (currentMutiply == 0)
        {
            return false;
        }
        return true;
    }
    public bool CanHealWisp()
    {
        return Unlock(SkillUpgradeType.TimeEnco_HealWisp)
            || Unlock(SkillUpgradeType.TimeEnco_CleanseWisp)
            || Unlock(SkillUpgradeType.TimeEnco_CooldownWisp);
    }
    public bool CanCoolDownReduce()
    {
        if (Unlock(SkillUpgradeType.TimeEnco_CooldownWisp))
            return true;
        return false;
    }
    public bool CanRemoveNegativeEffects()
    {
        if (Unlock(SkillUpgradeType.TimeEnco_CleanseWisp))
            return true;
        return false;
    }
    public float GetDamagePercentHeal()
    {
        if (CanHealWisp())
            return damagePercentHealed;
        return 0;
    }
    public float GetCooldownReducedInSeconds()
    {
        if (Unlock(SkillUpgradeType.TimeEnco_CooldownWisp))
            return cooldownReducedInSeconds;
        return 0;
    }
    public float GetMultiplyProbability()
    {
        if (Unlock(SkillUpgradeType.TimeEnco_ChanceToMultiply))
            return multiplyProbability;
        return 0;
    }
    
    public int GetAttackCount()
    {
        if (Unlock(SkillUpgradeType.TimeEnco_SingleAttack) || Unlock(SkillUpgradeType.TimeEnco_ChanceToMultiply))
            return singleAttackCount;
        if (Unlock(SkillUpgradeType.TimeEnco_MutiAttack) )
            return maxAttackCount;
        return 0;
    }
    public void CreateTimeEcho(Vector2? position = null)
    {
        Vector2 targetPosition = (Vector2)(position != null ? position : transform.position);
        GameObject prefab = Instantiate(regularTimeEchoPrefab, targetPosition, Quaternion.identity);
        prefab.GetComponent<SkillObject_TimeEcho>().SetUpTimeEcho(this);
        SetSkillOnCoolDown();
    }
}
